import pandas as pd
from openpyxl import load_workbook


def xximport(xx_path, tax_path):
    zp_path = xx_path + '专普票.xls'
    dz_path = xx_path + '电子票.xls'
    zpfp = pd.read_excel(zp_path, sheet_name=0, dtype='str')
    dzfp = pd.read_excel(dz_path, sheet_name=0, dtype='str')
    dzfp['报送日志'] = ''
    dzfp['清单标志'] = ''
    dzfp['打印标志'] = ''
    dzfp['发票状态'] = ''
    dzfp['作废日期'] = ''
    dzfp['发票代码'] = dzfp['类别代码']
    dzfp['合计金额'] = dzfp['金额']
    dzfp['合计税额'] = dzfp['税额']

    dzfp = dzfp[['发票种类', '发票代码', '发票号码', '购方税号', '购方名称', '开票日期', '主要商品名称', '报送状态', '报送日志', '合计金额', '税率', '合计税额', '清单标志', '打印标志', '作废标志', '发票状态', '作废日期', '备注', '开票人', '收款人', '复核人']]
    dzfp = dzfp[dzfp['合计金额'].notna()]
    print(dzfp)
    xxfp = pd.concat([zpfp, dzfp])
    print(xxfp)
    with pd.ExcelWriter(tax_path, engine='openpyxl', mode='a', if_sheet_exists='replace') as writer:
        book = load_workbook(tax_path)
        writer.book = book  # 读取excel
        writer.sheets = dict((ws.title, ws) for ws in book.worksheets)  # 复制excel的所有表
        xxfp.to_excel(writer, sheet_name='基础表1', startrow=1, index=None)
